package com.mxchip.livestar.ui.network.wifi.view


import android.content.Context
import android.net.ConnectivityManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.mxchip.livestar.R
import kotlinx.android.synthetic.main.fragment_network_main.*
import java.text.SimpleDateFormat


class SettingFragment : Fragment() {

    private val formatter = SimpleDateFormat("yyyy-MM-dd")

    private var count = 1


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_network_main, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)



        view2.setOnClickListener {

            findNavController().navigate(R.id.mainToWlan)
        }

        view_ethernet.setOnClickListener {
            if (!isEthernet(requireContext())){
                Toast.makeText(requireContext(),"请连接有线网络",Toast.LENGTH_LONG).show()
                return@setOnClickListener
            }
            findNavController().navigate(R.id.mainToEthernet)
        }

    }
    fun isEthernet(context: Context): Boolean {
        val connectMgr = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val ethNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET)
        return ethNetInfo != null && ethNetInfo.isConnected
    }
}
